<template>
	<div>
		<!-- 添加或修改安全检查单对话框 -->
    <el-dialog :title="title" center :visible.sync="open" width="720px" @close="close" append-to-body>
      <el-tabs v-model="activeName">
        <el-tab-pane label="流程表单" name="first">
          <ViewTab ref="viewTab" :form="form"></ViewTab>
        </el-tab-pane>
        <el-tab-pane label="检查指标" name="second">
          <ItemTab ref="itemTab" :data="form.labSafetyCheckIndexList" :instanceId="form.instanceId"></ItemTab>
        </el-tab-pane>
        <el-tab-pane label="流程签批" name="thrird" v-if="form.flowStatusOpt!='uncommitted'">
          <TaskApproval ref="task" @refresh="reload" :instanceId="form.instanceId"></TaskApproval>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
	</div>
</template>
<script>
import { getCheckedList } from "@/api/labdata/employee"
import { getCheckedList as getOrgCheckedList} from "@/api/labdata/orgnization"
import ViewTab from "../view/viewTab.vue"
import ItemTab from "../view/itemTab.vue"
import TaskApproval from '@/views/labdata/flowTask/task_approval.vue'
import { getLabsafetyForm } from "@/api/labsafety/labsafetyForm";
export default {
  name: "ViewDialog",
  components: { ViewTab, ItemTab, TaskApproval },
  data() {
    return {
      title: '南京邮电大学实验室安全检查',
      activeName: 'first',
      open: false,
      form: {},
    };
  },
  created() {
  },
  methods: {
    reload(){
      this.$emit("refresh");
      this.$forceUpdate();
    },
    /** 更新按钮操作 */
    handleView(id) {
      this.reset()
      this.activeName = 'first'
      this.open = true;
      getLabsafetyForm(id).then(response => {
        this.form = response.data;
        if (this.form.copyToUsers) {
          getCheckedList({checkedUserIds: this.form.copyToUsers}).then(res=>{
            this.$refs["viewTab"].copyToUsers = res.data
          });
        } else {
            this.$refs["viewTab"].copyToUsers = []
        }
        if (this.form.checkUsers) {
          getCheckedList({checkedUserIds: this.form.checkUsers}).then(res=>{
            this.$refs["viewTab"].checkUsers = res.data
          });
        } else {
            this.$refs["viewTab"].checkUsers = []
        }
        if (this.form.reviewUsers) {
          getCheckedList({checkedUserIds: this.form.reviewUsers}).then(res=>{
            this.$refs["viewTab"].reviewUsers = res.data
          });
        } else {
            this.$refs["viewTab"].reviewUsers = []
        }
        if (this.form.checkTargetOrgs) {
          getOrgCheckedList({checkedOrgIds: this.form.checkTargetOrgs}).then(res=>{
            this.$refs["viewTab"].checkTargetOrgs = res.data
          });
        } else {
            this.$refs["viewTab"].checkTargetOrgs = []
        }
        this.$refs["viewTab"].fileList = []
        if (this.form.files) {
            this.$refs["viewTab"].fileList = this.form.files
        }
      })
    },
    /** 更新按钮操作 */
    handleUpdate(row) {
      this.handleView(row.instanceId)
    },
    close() {
      this.activeName = 'first'
      this.open = false
    },
    // 取消按钮
    cancel() {
      this.close();
      this.reset();
    },
    reset() {
      this.form = {}
    }
  }
};
</script>
<style type="text/css" scoped>
</style>